'''
Created on 15-Jul-2010

@author: dexen
'''
import os
import time
import random

from dexen.system.base import task
from dexen.system.base.individual import Individual

import constants

def evaluate(ind):
    print "The current working directory is ", os.getcwd()
    path = os.path.join(os.getcwd(), "energyplusbasefile")
    filename  = "overhangschema"
    idf = ind.phen_energy
    idf.execute_idf(path, filename)
    result = idf.eval_idf("energytransfer")
    ind.score_energy = result
    ind.archive_data("score_energy.txt", ind.score_energy)

def evaluate_test(ind):
    assert isinstance(ind, Individual)
    time.sleep(random.randint(1,2))
    ind.score_energy = random.randint(10, 1000)
    ind.archive_data("score_energy.txt", ind.score_energy)
    
class EvalEnergyTask(task.Task):
    def __init__(self):
        pass
    
    def __execute__(self, inds=[]):    
        for ind in inds:
            evaluate(ind)
        return inds
    
    def __isvalid__(self, ind):
        return ind.phen_energy != None and ind.score_energy == None and ind.score_daylight == None
